package com.shujia.java.day14.ListToMapDemo1;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/**
 * list->map
 */
public class ListToMap {
    public static void main(String[] args) {
        //创建list 创建map 创建student
        ArrayList<Student> list = new ArrayList<Student>();
        HashMap<Integer, Student> map = new HashMap<Integer, Student>();
        //使用构造创建student
        Student student = new Student(10001,"张三",18,"男");
        Student student1 = new Student(10002,"李四",18,"男");
        Student student2 = new Student(10003,"王五",18,"男");
        Student student3 = new Student(10004,"赵六",18,"男");

        Student student4 = new Student(10004,"赵六",18,"男");

        //添加到list
        list.add(student);
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);

        // list中的student id做key student作为value
        //遍历 获取list中每一个student
        for (Student s:list) {
           // System.out.println(s.getName());
            map.put(s.getId(),s);
        }
        //遍历map 获取所有key
        Set<Integer> integers = map.keySet();
        for (Integer i:integers){
            //输出id 和name
            System.out.println(i+"--------------"+map.get(i).getName());
        }
        //Entry



    }

}
